//
//  ITDownloader.h
//  InduceTool
//
//  Created by 魏延龙 on 2020/9/9.
//  Copyright © 2020 魏延龙. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN


typedef NS_ENUM(NSUInteger, ITDownloaderError) {
    ITDownloaderErrorInvalidURL = 0,
    ITDownloaderErrorHTTPError,
    ITDownloaderErrorNotEnoughFreeDiskSpace
};

typedef NS_ENUM(NSUInteger, ITDownloaderState) {
    ITDownloaderReady = 0,
    ITDownloaderDownloading,
    ITDownloaderDone,
    ITDownloaderCancelled,
    ITDownloaderFailed
};

@interface ITDownloader : NSOperation

@property (nonatomic, assign) ITDownloaderState state;

- (instancetype)initWithUrl:(NSString *)url;

- (instancetype)initWithUrl:(NSString *)url toPath:(NSString *)path
                   progress:(void (^)(uint64_t receivedLength, uint64_t totalLength, NSInteger remainingTime, float progress))progressBlock
                      error:(void (^)(NSError *error))errorBlock
                   complete:(void (^)(BOOL downloadFinished, NSString *pathToFile))completeBlock;

- (void)cancel;
@end

NS_ASSUME_NONNULL_END
